home *** CD-ROM | disk | FTP | other *** search
- Path: crl.crl.com!not-for-mail
- From: bobfry@crl.com (Robert Fry)
- Newsgroups: comp.lang.c
- Subject: Re: Q: tokenizing
- Date: 8 Mar 1996 08:35:32 -0800
- Organization: CRL Dialup Internet Access
- Message-ID: <4hpnkk$lkh@crl.crl.com>
- References: <maguirer.826209754@hercules>
- NNTP-Posting-Host: crl.com
-
- maguirer@HERCULES.CS.UREGINA.CA (Rob Maguire) writes:
-
- >Have read the FAQ and found the question where it talks about separating a
- >string into tokens split by white-space. The answer is to use 'strtok'.
-
- >OK... How?
-
- >Have tried, with little luck so far.
-
- What do you have so far? An example of how far you've gotten might help.
-
- Here's an off-the-cuff example (which is probably buggy, as I can't check
- it easily):
-
- char string[] = "A sample string to be made into tokens";
- char *tokens[10];
- int i;
-
- tokens[ 0] = strtok( string, " ");
- for ( i = 1; tokens[ i - 1]; i++)
- tokens[ i] = strtok( string, NULL);
-
- /* When you leave the loop, tokens[ 0] points to "A", tokens[ 1] points
- to "sample", tokens[ 2] points to "string", and so on. */
-
- Note that this example's completely lacking in error checking, and if I
- was willing to take the time, I'd probably put in a big comment about the
- loop condition.
-
- Bob
-